﻿using CSC;
using CSC.Managers;
using System;
using System.Windows;
using System.Windows.Controls;

namespace JDGLSys.Forms.Pages.LoginFormPages
{
    /// <summary>
    /// ResetPage.xaml 的交互逻辑
    /// </summary>
    public partial class ResetPage : Page
    {
        public ResetPage()
        {
            InitializeComponent();
        }
        private int sendEmailYz()
        {
            Random random = new Random();
            //6位验证码
            int code = random.Next(100000, 999999);
            string message = "您正在密码重置，这是您的密码重置验证码:\r\n" + code;
            EmailHelper.Sendmail(EmailTxt.Text, "密码重置", message);
            return code;
        }
        int code = 0;
        private void sendEmailYZ_Btn_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            code = sendEmailYz();
            MessageBox.Show("验证码已发送，如未收到请重新发送");
        }

        private void resetBtn_Click(object sender, RoutedEventArgs e)
        {
            if (code.ToString().Equals(YzCodeTxt.Text))
            {
                UsersTManager.updatePwd(PasswordTxt.Password, EmailTxt.Text);
                MessageBox.Show("密码已重置");
            }
            else
                MessageBox.Show("验证码错误，请重新输入");
        }
    }
}
